"""
    递归算法的一般思想就是自己调用自己，一般的方法就是, 判断-> 递归
下面是一些相关的例子
"""
# 进行阶乘计算
def max(n):
    if n < 1:
        return 1
    return n*max(n-1)

# 斐波那契数列
def fib(n):
    if (n<1):
        return 1
    return fib(n-1)+fib(n-2)


# 二叉树遍历
class Btree(object):
    def __init__(self,left,right,data):
        self.left = left
        self.right = right
        self.data = data

    # 前
    def preorder(self):
        if self.data is not None:
            print(self.data)
        if self.left is not None:
            self.left.preorder()
        if self.right is not None:
            self.right.preorder()

    # 中
    def inorder(self):
        if self.left is not None:
            self.left.preorder()
        if self.data is not None:
            print(self.data)
        if self.right is not None:
            self.right.preorder()

    # 后
    def postorder(self):
        if self.left is not None:
            self.left.preorder()
        if self.right is not None:
            self.right.preorder()
        if self.data is not None:
            print(self.data)

